//用于显示测试系统详情两个板块的可编辑tabPanel
var testSystemEditorTabPanel = Ext.create('Ext.tab.Panel',{
	defaults:{
		layout:'fit'
	},
	items : [ {
		title : '详细信息',
		itemId:'detailForm',
		items : [testSystemDetailEditorForm]
	}, {
		title : '系统附件',
		itemId:'attachedList',
		items : [testSystemAttachedEditorGrid]
	}],
	buttons:[{
		text:'返回',
		listeners:[{
			click:function(){
				Ext.getCmp('centerRegion').removeAll(false);
            	Ext.getCmp('westRegion').setHidden(true);
            	testSystemGridStore.reload();
            	Ext.getCmp('centerRegion').add(testSystemEditorGrid);
			}
		}]
	},{
		text:'保存',
		itemId:'saveButton',
		listeners:[{
			click:function(){
				if(testSystemDetailEditorForm.isValid()){
					testSystemEditorTabPanel.down('#saveButton').setDisabled(true);
					var testSystemId;
					if(testSystrmIsCreate==1)//如果现在是新建操作
						testSystemId=Ext.create("MyApp.data.MyModelX").data.id.replace(/-/g, "");//自己生成Id
					else
						testSystemId=testSystemEditorTabPanel.systemId;
					var fd = new FormData();
					var name=testSystemDetailEditorForm.down('#name').getValue();
					var type=testSystemDetailEditorForm.down('#type').getValue();
					var describe=testSystemDetailEditorForm.down('#describe').getValue();
					fd.append("id",testSystemId);
					fd.append("name",name);
					fd.append("type",type);
					fd.append("describe",describe);
					fd.append("addMan",currentUserId);//添加人和开发者不知道写谁，先写本人先
					fd.append("devMan",currentUserId);
					fd.append("currentUserId",currentUserId);
					var attaList=testSystemAttachedStore.getData();
					var attaArray=new Array();
					Ext.each(attaList.items,function(record){//向formData添加附件列表
						var object=new Object();
						object['id']=record.data.id;
						object['name']=record.data.name;
						object['type']=record.data.type;
						object['system']=testSystemId;
						attaArray.push(object);
					});
					fd.append("attachedList",JSON.stringify(attaArray));//因为formData里面不能直接放对象，所以先转成json字符串
					for(var i=0,length=testSystemFileArray.length;i<length;i++){//向formData添加附件文件
						fd.append("attachedFiles", testSystemFileArray[i]);
					}
					Ext.Ajax.request({
		                  url: zuulUrl + '/' + testServiceName + '/testSystem',
		                  async: false,   //ASYNC 是否异步( TRUE 异步 , FALSE 同步)
		                  method: testSystrmIsCreate==1?'post':'put',
		                  rawData:fd,
		                  headers: {
		                      "Content-Type":null   /* 最重要的部分，将Content-Type设置成null，ExtJs则会由内部的XMLHTTPRequest自动生成包含boundary的Content-Type，否则在使用rawData的情况下，ExtJs会将Content-Type设置成text/plain */
		                  },
		                  success: function (response, opts) {
		                    Ext.Msg.alert('成功', '保存成功');
		                    testSystrmIsCreate=0;//标注现在是编辑操作
		                    testSystemGridStore.reload();
		                    Ext.each(attaList.items,function(record){//向formData添加附件列表
								record.data.isCreate=false;//将新上传的附件标为不是新添加的
							});
		                    testSystemFileArray=[];//清空formData储存内容
		                  },
		                  failure: function (response, opts) {
		                	  Ext.Msg.alert('错误', '该功能暂时不可用');
		                  }
					});
					testSystemEditorTabPanel.down('#saveButton').setDisabled(false);
				}else
					Ext.Msg.alert('错误', '测试系统信息请填写完全！');
			}
		}]
	}]
});